package com.itheima.d11_proxy.demo;

import java.time.Instant;

public class UserServiceImpl implements UserService {
    @Override
    public String login(String loginName, String passWord) {
//        long startTimer = System.currentTimeMillis();
        sleep(500);
        if ("admin".equals(loginName) && "1234".equals(passWord)) {
//            long endTimer = System.currentTimeMillis();
//            System.out.println("login 方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");

            return "success";
        }

        return "登录名和密码可能有毛病";

    }

    @Override
    public void selectUsers() {
//        //开始时间
//        long startTimer = System.currentTimeMillis();

        //业务逻辑
        sleep(1500);
        System.out.println("查询了100个用户数据！");

//        //结束时间
//        long endTimer = System.currentTimeMillis();
//
//        //统计结果
//        System.out.println("selectUsers 方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");

    }

    @Override
    public boolean deleteUsers() {
//        long startTimer = System.currentTimeMillis();
        sleep(800);
        System.out.println("删除100个用户数据！");

//        long endTimer = System.currentTimeMillis();
//        System.out.println("deleteUsers 方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");

        return true;


    }

    @Override
    public void updateUsers() {
//        long startTimer = System.currentTimeMillis();

        sleep(200);
        System.out.println("修改100个用户数据！");
//        long endTimer = System.currentTimeMillis();
//
//        System.out.println("updateUsers 方法耗时：" + (endTimer - startTimer) / 1000.0 + "s");


    }

    public void sleep(long time){
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
